package com.dyz.swordFingerOffer;

import java.util.ArrayList;

public class FirstAppearingOnce {
    //Insert one char from stringstream
    private ArrayList<Character> ans = new ArrayList<>();
    private ArrayList<Integer> count = new ArrayList<>();
    //创建两个数组，一个存储字符，一个存储次数
    public void Insert(char ch)
    {
        if(ans.contains(ch)){
            int index = ans.indexOf(ch);
            count.set(index,count.get(index)+1);

        }else{
            ans.add(ch);
            count.add(1);
        }
    }
    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce()
    {
        if(count.size()>0){
            for(int i=0; i<count.size();i++){
                if(count.get(i)==1){
                    return ans.get(i);
                }
            }
        }
        return '#';
    }
}
